package com.hc.likelistenmusic.manager;

import android.app.Activity;

import java.lang.ref.WeakReference;

public class ActivityManager {
    private static WeakReference<Activity> activityWeakReference;
    private static Object lock = new Object();

    public static Activity getCurrentActivity(){
        Activity current = null;
        synchronized (lock){
            if(activityWeakReference != null){
                current = activityWeakReference.get();
            }
        }
        return current;
    }

    public static void setCurrentActivity(Activity activity){
        synchronized (lock){
            activityWeakReference = new WeakReference<>(activity);
        }
    }
}
